#!/bin/bash

start()
{
	env LANG=C mrtg --pid-file=/var/run/mrtg-daemon.pid /etc/mrtg/mrtg.cfg --lock-file=/var/run/mrtg.lock #1> /dev/null 2> /dev/null
	if [ $? == 0 ]; then
		echo -e "MRTG Daemon Started \t\t\t[OK]"
		exit 0
	else 
		echo -e "MRTG Daemon Failed \t\t\t[Fail]"
		exit 1
	fi
}


stop()
{

	kill -9 $(cat /var/run/mrtg-daemon.pid) 1> /dev/null 2> /dev/null
	if [ $? == 0 ]; then
		echo -e "MRTG Daemon Stopped \t\t\t[OK]"
	else
		echo -e "MRTG is not Running \t\t\t[OK]"
	fi	
}


case $1 in
	'start')
		start
	;;
	'stop')
		stop
	;;
	'restart')
		stop
		start
	;;		
	*)
		echo 'usage $0 { start | stop | restart }'
	;;
esac
